function main(){
    debugger
    const self = this;
    window.selectMatter = window.selectMatter || [{
        id: '',
        uid: '',
        rec_id: '', // 案件id
        rec_task_num: '',   // 案件编号
        matter_id: '',  //
        rec_rel_matter_name: '',
        rec_rel_matter_id: '',
        law_code: '',
        law_name: '',
        law_set_basis_type_code: '',
        law_set_basis_type_name: '',
        law_item_id: '',
        law_item_code: '',
        law_item_name: '',
        law_item_info: '',
        opt_type: '',
        create_time: '',
        update_time: ''
    }];

    let tableEle = self.$$("table_eweksq");

    let selectMatter = tableEle.$$getSelection().selectedRows;
    if (selectMatter.length === 0){
        self.$message.warning("请选择对应的法规依据");
        return false;
    }

    let recId = (self.$$("number_input_happ9m") && self.$$("number_input_happ9m").cValue) || null;
    let recTaskNum = (self.$$("text_input_1ay7ts") && self.$$("text_input_1ay7ts").cValue) || null;
    let matterId = '';
    let recRelMatterName = (self.$$("widget_list_picker_gz6a75") && self.$$("widget_list_picker_gz6a75").cValue) || '';
    let lawSetBasisTypeCode = (self.state.extraParams || {})["lawSetBasisTypeCode"];
    let lawSetBasisTypeName = (self.state.extraParams || {})["lawSetBasisTypeName"];

    const newItems = selectMatter.map(item => ({
        rec_id: recId,
        rec_task_num: recTaskNum,
        matter_id: matterId,
        rec_rel_matter_name: recRelMatterName,
        law_code: item.law_code.value,
        law_name: item.law_name.value,
        law_set_basis_type_code: lawSetBasisTypeCode,
        law_set_basis_type_name: lawSetBasisTypeName,
        law_item_id: item.id.value,
        law_item_code: item.contentCode.value,
        law_item_name: item.contentName.value,
        law_item_info: item.contentDesc.value,
        opt_type: 'I',
        document_id: lawSetBasisTypeCode + item.id.value,
    }));

    if (window.selectMatter && window.selectMatter.length > 0 &&
        window.selectMatter[0].law_item_id !== undefined) {

        newItems.forEach(newItem => {
            const exists = window.selectMatter.some(existingItem =>
                existingItem.law_item_id === newItem.law_item_id &&
                existingItem.law_set_basis_type_code === newItem.law_set_basis_type_code
            );

            if (!exists) {
                window.selectMatter.push(newItem);
            } else {
               return false;
            }
        });
    } else {
        window.selectMatter = newItems;
    }

    let selectItemEle =  window.tableELe;

    selectItemEle.onRefresh();
    //law_std_rec_matter_rel_set_basis
    notifyParentAndClose(this)
}

function notifyParentAndClose(self) {
    if (window.parent) {
        window.parent.postMessage(
            JSON.stringify({ event: "close-dialog", param: { XXX: "test" } }),
            "*"
        );
    }
}


/**
 * 法规查询带回
 * @param params
 */
function main(params) {
    debugger;
    const self = this;
    window.selectMatter = window.selectMatter || [{
        id: '',
        uid: '',
        rec_id: '', // 案件id
        rec_task_num: '',   // 案件编号
        matter_id: '',  //
        rec_rel_matter_name: '',
        rec_rel_matter_id: '',
        law_code: '',
        law_name: '',
        law_set_basis_type_code: '',
        law_set_basis_type_name: '',
        law_item_id: '',
        law_item_code: '',
        law_item_name: '',
        law_item_info: '',
        opt_type: '',
        create_time: '',
        update_time: ''
    }];

    let recId = (self.$$("number_input_happ9m") && self.$$("number_input_happ9m").cValue) || null;
    let recTaskNum = (self.$$("text_input_1ay7ts") && self.$$("text_input_1ay7ts").cValue) || null;
    let matterId = params.matterId.value;
    let recRelMatterName = params.matterName.value;

    let wzLawCode = params.wzLawCode.value;
    let wzLawName = params.wzLawName.value;
    let wzLawSetBasisTypeCode = 2;
    let wzLawSetBasisTypeName = '违则依据';
    let wzLawItemId = params.wzItemId.value;
    let wzLawItemCode = params.wzLawItemCode.value;
    let wzLawItemName = params.wzLawItemName.value;
    let wzLawItemInfo = params.wzLawItemInfo.value;

    let fzLawCode = params.fzLawCode.value;
    let fzLawName = params.fzLawName.value;
    let fzLawSetBasisTypeCode = 1;
    let fzLawSetBasisTypeName = '罚则依据';
    let fzLawItemId = params.fzItemId.value;
    let fzLawItemCode = params.fzLawItemCode.value;
    let fzLawItemName = params.fzLawItemName.value;
    let fzLawItemInfo = params.fzLawItemInfo.value;

    window.selectMatter.push({
        rec_id: recId,
        rec_task_num: recTaskNum,
        matter_id: matterId,
        rec_rel_matter_name: recRelMatterName,
        law_code: wzLawCode,
        law_name: wzLawName,
        law_set_basis_type_code: wzLawSetBasisTypeCode,
        law_set_basis_type_name: wzLawSetBasisTypeName,
        law_item_id: wzLawItemId,
        law_item_code: wzLawItemCode,
        law_item_name: wzLawItemName,
        law_item_info: wzLawItemInfo,
        opt_type: 'I',
        document_id: wzLawSetBasisTypeCode + wzLawItemId,
    });

    window.selectMatter.push({
        rec_id: recId,
        rec_task_num: recTaskNum,
        matter_id: matterId,
        rec_rel_matter_name: recRelMatterName,
        law_code: fzLawCode,
        law_name: fzLawName,
        law_set_basis_type_code: fzLawSetBasisTypeCode,
        law_set_basis_type_name: fzLawSetBasisTypeName,
        law_item_id: fzLawItemId,
        law_item_code: fzLawItemCode,
        law_item_name: fzLawItemName,
        law_item_info: fzLawItemInfo,
        opt_type: 'I',
        document_id: fzLawSetBasisTypeCode + fzLawItemId,
    })


    let selectItemEle = self.$$("table_40gghs");
    selectItemEle.onRefresh();

    if (window.parent) {
        window.parent.postMessage(JSON.stringify({
            event: "close-dialog",
            param: { "XXX": "test" }
        }), "*");
    }

}
